﻿using B.S.Data.MES.API.Applications.QualityManagement.ExamineMaterialsCommand.Commands;
using B.S.Data.MES.API.Applications.QualityManagement.ExamineTypeModel.Command;
using B.S.Domain.BasicData.QualityManagement;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;
using Yitter.IdGenerator;

namespace B.S.Data.MES.API.Applications.QualityManagement.ExamineMaterialsCommand.CommandHandlers
{
    public class ExamineMaterisalCommandHandler : IRequestHandler<ExamineMaterisalCommand, APIRequst<int>>
    {
        private readonly IBaseRepository<MaterialsExamine> _materialsexamineRepository;
        public ExamineMaterisalCommandHandler(IBaseRepository<MaterialsExamine> materialsexamineRepository)
        {
            _materialsexamineRepository = materialsexamineRepository;
        }
        public async Task<APIRequst<int>> Handle(ExamineMaterisalCommand request, CancellationToken cancellationToken)
        {
            APIRequst<int> result = new APIRequst<int>();
            result.Code = RequstCode.成功;
            result.Msg = RequstCode.成功.ToString();
            MaterialsExamine mater = new MaterialsExamine();
            mater.MaterialNo = YitIdHelper.NextId().ToString();
            mater.MaterialsName = request.MaterialsName;
            mater.DesignName = request.DesignName;
            mater.BatchNumber = request.BatchNumber;
            mater.Suppliername = request.Suppliername;
            mater.MaterialCount = request.MaterialCount;
            mater.CreateName = request.CreateName;
            mater.CreateTime = DateTime.Now;

            await _materialsexamineRepository.Add(mater);

            return await Task.FromResult(result);


        }
    }
}
